package com.majun.util;

import java.security.MessageDigest;

/**
 * MD5加密工具类
 * @author pibigstar
 *
 */
public class MyMD5Util {
	//盐，用于混交md5
//	private static final String slat = "&%5123***&&%%$$#@";
//	private static final String slat = "uiwueylm";
	private static final String slat = "eteokues";
	public static String encrypt(String dataStr) {
		try {
			dataStr = dataStr + slat;
			MessageDigest messageDigest = MessageDigest.getInstance("MD5");
			messageDigest.update(dataStr.getBytes("UTF8"));
			byte s[] = messageDigest.digest();
			String result = "";
			for (int i = 0; i < s.length; i++) {
				result += Integer.toHexString((0x000000FF & s[i]) | 0xFFFFFF00).substring(6);
			}
			return result;
		} catch (Exception e) {
			e.printStackTrace();
		}

		return "";
	}

	public static void main(String[] args) {
		// 原密码
//        String plaintext = "123456";
//
//        // 获取加盐后的MD5值
//        String ciphertext = MD5Utils.getSaltMD5(plaintext);
//        System.out.println("加盐后MD5：" + ciphertext);
//        System.out.println("是否是同一字符串:" + MD5Utils.getSaltverifyMD5(plaintext, ciphertext));


		String password = "123456";
		String salt = "uiwueylm";
//        String salt = "uiwueylm";
		String md5FromSalt = encrypt(password);
		System.err.println(md5FromSalt);
	}

}

